package com.rainman.noswagger.info_bean;


import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.VariableDeclarator;
import com.rainman.noswagger.NoSwaggerCore;
import com.rainman.noswagger.core.BaseBean;
import lombok.Data;


@Data
public class FiledInfoBean extends BaseBean {
    private FieldDeclaration fieldDeclaration;
    private VariableDeclarator variableDeclarator;


    /**
     * 类名
     */
    private String typeClassName;

    /**
     * 描述
     */
    private String descStr;

    public FiledInfoBean(FieldDeclaration fieldDeclaration, VariableDeclarator variableDeclarator
            , NoSwaggerCore core, ClassInfoBean classInfoBean){
        super(variableDeclarator.getNameAsString(),core,fieldDeclaration.getAnnotations(),fieldDeclaration.getComment());
        this.fieldDeclaration=fieldDeclaration;
        this.variableDeclarator=variableDeclarator;


        typeClassName=variableDeclarator.getTypeAsString();

        if(getOriCommentStr()==null){
            return;
        }
        String[] split = getOriCommentStr().split("\n");
        for(int ii=0;ii<split.length;ii++){
            String s=split[ii];
            if(s.trim().length()<=0){
                continue;
            }
            s = s.replaceFirst(" \\*", "");

            if(s.trim().length()>0){

                if(descStr==null){
                    descStr =  s.trim();
                }else {

                    descStr += "\n" + s.trim();
                }
            }
        }



    }

/*    public JSONObject getInfo() {
        JSONObject reJson=new JSONObject();
        reJson.set("typeClassName",typeClassName);
        reJson.set("name",getName());
        reJson.set("descStr",descStr);
        for (String key : getOtherInfo().keySet()) {
            reJson.set(key,getOtherInfo().get(key));
        }
        return reJson;
    }*/
}
